<%@ page contentType="text/html;charset=GBK"
	import="java.util.*, java.io.*, git.common.*, java.sql.PreparedStatement
	, git.etl.RecursiveFilesImporter, git.etl.IFileHandler
	, git.etl.acc.AccReportHtmlReader, git.etl.acc.AccReportTextReader
	, git.etl.Dao, java.sql.Connection, java.sql.ResultSet, java.sql.Statement" 
%><jsp:useBean id="oLogon" class="git.bankview.wl.bean.LogonBean" scope="session" 
/><%
	request.setCharacterEncoding("GBK");
	boolean isnew = (null != request.getParameter("isnew"));
	String transid = request.getParameter("transid");
	int labelorder = Integer.parseInt(transid);

	String translabel = request.getParameter("translabel");
	String ptransid = request.getParameter("ptransid");
	String pageurl = request.getParameter("pageurl");
	String transfunc = request.getParameter("transfunc");
	String typecode = null;
	String statuscode = "0";
	
	if ("UPLOADED".equals(transfunc))
	{
		pageurl = "/jsp/upload/UploadReportView.jsp?transid=" + transid;
	}
	
	Connection conn = Dao.getCogdbConnection();
	
	try
	{
		Statement pst = conn.createStatement();
		try
		{
			ResultSet rs = pst.executeQuery("select typecode from infotrans where transid = '" + ptransid + "'");
			try
			{
				if (rs.next())
					typecode = String.valueOf(rs.getInt(1) + 1);
			}
			finally
			{
				rs.close();
			}
		}
		finally
		{
			pst.close();
		}
		
		String sql = isnew ? "insert into infotrans (transfunc, translabel, ptransid, pageurl, labelorder, typecode, statuscode, transid) values (?,?,?,?,?,?,?,?)"
				: "update infotrans set transfunc = ?, translabel = ?, ptransid = ?, pageurl = ?, labelorder = ?, typecode = ?, statuscode = ? where transid = ?";
		
		PreparedStatement ps = conn.prepareStatement(sql);
		
		try
		{
			ps.setString(1, transfunc);
			ps.setString(2, translabel);
			ps.setString(3, ptransid);
			ps.setString(4, pageurl);
			ps.setInt(5, labelorder);
			ps.setString(6, typecode);
			ps.setString(7, statuscode);
			ps.setString(8, transid);
			
			ps.executeUpdate();
		}
		finally
		{
			ps.close();
		}
		
		if (isnew)
		{
			Statement st = conn.createStatement();
			try
			{
				st.addBatch("insert into transmethod values('" + transid + "', 1)");
				st.addBatch("insert into transmethod values('" + transid + "', 13)");
				st.addBatch("insert into transmethod values('" + transid + "', 255)");
				st.addBatch("insert into roletrans values('" + oLogon.getUsername() + "', '" + transid + "', 1, 0)");
				st.addBatch("insert into roletrans values('" + oLogon.getUsername() + "', '" + transid + "', 13, 0)");
				st.addBatch("insert into roletrans values('" + oLogon.getUsername() + "', '" + transid + "', 255, 0)");
				st.executeBatch();
			}
			finally
			{
				st.close();
			}
		}
	}
	finally
	{
		conn.close();
	}
%>
<h1>OK</h1>